<?php
/**
 * Created by PhpStorm.
 * User: ITS Lab
 * Date: 2015/9/26
 * Time: 0:08
 */
namespace Home\Controller;

use Think\Controller;

class InformationController extends Controller
{

    public function index()
    {
        header("Content-type:text/html;charset=utf-8");
        $_SESSION['href']='Information/index';
        //导航条的时间分类
        $today = date("Y-m-d");
        $yesterday = date("Y-m-d", strtotime("-1 day"));
        $twoDaysAgo = date("Y-m-d", strtotime("-2 day"));
        $threeDaysAgo = date("Y-m-d", strtotime("-3 day"));
        $fourDaysAgo = date("Y-m-d", strtotime("-4 day"));
        $fiveDaysAgo = date("Y-m-d", strtotime("-5 day"));
        $this->assign('today', $today);
        $this->assign('yesterday', $yesterday);
        $this->assign('twoDaysAgo', $twoDaysAgo);
        $this->assign('threeDaysAgo', $threeDaysAgo);
        $this->assign('fourDaysAgo', $fourDaysAgo);
        $this->assign('fiveDaysAgo', $fiveDaysAgo);
        //每一个失物招领启示的具体内容
        $lost_thing_record = D('kind')->getKindName();
        $this->FoundRecord = $lost_thing_record;
        $m=M('thing');
        $id=I('get.id');
        $_SESSION['thing_id']=$id;
        $where['id']=$id;
        $data=$m->where($where)->select();
        $this -> FoundRecord1 = $data;
        $this->thing_id=$id;
            $this->username=$_SESSION['username'];
            $this->uid=$_SESSION['uid'];
        $this -> display();
    }
    public  function  ajax()
    {
        $kind_id=I('post.kind_id');
        $where['id']=$kind_id;
        $m=M('kind');
        $data=$m->where($where)->find();
        $this->ajaxReturn($data['name']);
    }
    public  function  ajax_id() //处理认领要求
    {
        $id = I('post.thing_id');
        $where['id'] = $id;
        $m = M('thing');
        $status = $m->where($where)->field('status')->find();
        $status['status'] = 1;
       $m->where($where)->save($status);
        $m=M('user');
        $uid=$_SESSION['uid'];//通过uid去获取user表里对应的id
        $where1['bbs_uid']=$uid;
        $id2=$m->where($where1)->field('id')->find();
        $id1=$id2['id'];
        $where2['thing_id']=$id;
        $m=M('trade_record');
        $temp=$m->where($where2)->field('request_id')->find();
        $temp['request_id']=$id1;
        $temp['trade_time']=date("Y-m-d H:i:s");//更新交易时间
        $m->where($where2)->save($temp);
    }
      function _empty(){
        header("HTTP/1.0 404 Not Found");//使HTTP返回404状态码
        $this->display("Error:error404");
    }
}